//var __SERVICE_URL_PREFIX__="/web-proxy/vservices/";
var __SERVICE_URL_PREFIX__="http://localhost:8084/index.php/Index/";

$(document).ready( function(){
	//noty({ text: "提示信息~~~~~" });
	keywordSearchForm.keywordSearch();//查询视频
	//popularForm.popular();
});

/***
 * 显示load到层
 */
function showLoading(showId){
	$("#loadingDiv" ).tmpl("").appendTo("#"+showId);
}

var keywordSearchForm ={
	keywordSearch : function(){
		var keyword =$("#keyword").val();
		//keywordSearch : function(keywords, perPage, pageNumber, callback) {
		showLoading("contentId");
		srvReq.keywordSearch(keyword,"1","20",fillData);
	}
};

//填充数据到contentId div 中去
function fillData(data){
  $("#contentId").html("");
  if(data.error.code==200){
	  	if(data.data.total!=undefined && data.data.total!=0){
		    var count = data.data.list.length;//list.length;
			for(var i=0;i<count;i++){
				$("#sousuo" ).tmpl(data.data.list[i]).appendTo("#contentId" );
				/**
				//分页，PageCount是总条目数，这是必选参数，其它参数都是可选
				 $("#Pagination").pagination(pageRowCount, {
			           callback: PageCallback,
			           prev_text: '上一页',       //上一页按钮里text
			           next_text: '下一页',       //下一页按钮里text
			           items_per_page: pageSize,  //显示条数
			           num_display_entries: 5,    //连续分页主体部分分页条目数
			           current_page: pageIndex,   //当前页索引
			           num_edge_entries: 2        //两侧首尾分页条目数
			     });
			     **/
			}
			if(count==undefined || count==0){
				//noty($.parseJSON('{"text":"无相关数据","layout":"center","type":"error"}'));
				noty({text: "无相关内容", layout: "center", timeout: 5000});
			}
		}else{
			  noty({text: "无相关内容", layout: "center", timeout: 5000});
		 }
  }else{
	  noty($.parseJSON('{"text":"'+data.error.message+'","layout":"center","type":"error"}'));	
  }
}

var popularForm={
	popular: function(){
		var area =$("#keyword").val();
		if(area==null || area==''){
			area="News";
		}
		showLoading("hotDivId");
		srvReq.popular(area,fillHotData);
	}
};
/**
 * 填充fillHotData
 */
function fillHotData(data){
  $("#hotDivId").html("");
  if(data.error.code==200){
	  if(data.data.total!=undefined && data.data.total!=0){
	    var count =data.data.list.length;//.length;// data.data.count;
		for(var i=0;i<count;i++){
			$("#hotTmpl" ).tmpl(data.data.list[i]).appendTo("#hotDivId" );
		}
		if(count==undefined || count==0){
			//noty($.parseJSON('{"text":"无相关数据","layout":"center","type":"error"}'));
			noty({text: "无相关热点数据", layout: "center", timeout: 5000});
		}
	  }else{
		  noty({text: "无相关热点数据", layout: "center", timeout: 5000});
	  }
  }else{
	  noty($.parseJSON('{"text":"'+data.error.message+'","layout":"center","type":"error"}'));	
  }
}